﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace Clarius.Silverlight.Streaming.Library.Operations
{
    internal class DeleteFileSetOperation : SilverlightStreamingOperation
    {
        String fileSetName;

        internal DeleteFileSetOperation(AccountManager accountManager, String fileSetName)
        {
            this.fileSetName = fileSetName;
            base.Initialize(accountManager);
        }

        protected override WebRequest GetWebRequest()
        {
            WebRequest request = WebUtil.GetWebRequest(accountManager.Account, "/" + fileSetName);
            request.Method = WebUtil.HTTP_METHOD_DELETE;

            return request;
        }

        protected override void HandleErrorFromHttpStatusCode(HttpStatusCode statusCode, String errorText, Exception ex)
        {
            switch (statusCode)
            {
                case HttpStatusCode.NotFound:
                    throw new SilverlightStreamingException("FileSet not found", ex);
            }

            throw new SilverlightStreamingException(errorText, ex);
        }
    }
}
